package com.easthome.common.handler;

import com.easthome.common.result.Result;
import com.easthome.common.result.ResultCodeEnum;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @description:
 * @author: 朱敦宇
 * @time: 2023/11/6 17:46
 */
@RestControllerAdvice
public class GlobalException  {
    @ExceptionHandler(RuntimeException.class)
    public Result runtimeExcption(RuntimeException e){
        e.printStackTrace();
        return Result.build(null, ResultCodeEnum.SERVICE_ERROR);
    }
    @ExceptionHandler(UsernameNotFoundException.class)
    public Result arithmeticException(ArithmeticException e){
        return Result.build(null,ResultCodeEnum.LOGIN_USER_ERROR);
    }
    @ExceptionHandler(EasthomeException.class)
    public Result easthomeException(EasthomeException e){
        e.printStackTrace();
        return Result.build(null,e.code,e.message);
    }
}
